package cn.lingyangwl.agile.msg.push.model;

import cn.lingyangwl.agile.msg.push.api.constatnts.ChannelTypeEnum;
import cn.lingyangwl.agile.msg.push.model.entity.Receiver;
import cn.lingyangwl.framework.tool.core.StringUtils;
import lombok.Data;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * 接收者配置信息
 * @author shenguangyang
 */
@Data
public class ReceiverConfig {
    private ChannelTypeEnum channelType;
    private String toUser;

    public static List<ReceiverConfig> of(Receiver receiver) {
        List<ReceiverConfig> list = new ArrayList<>();

        if (StringUtils.isNotEmpty(receiver.getPhone()) && Objects.equals(receiver.getPhoneStatus(), Receiver.Status.VERIFY)) {
            ReceiverConfig resp = new ReceiverConfig();
            resp.setChannelType(ChannelTypeEnum.SMS);
            resp.setToUser(receiver.getPhone());
            list.add(resp);
        }

        if (StringUtils.isNotEmpty(receiver.getEmail()) && Objects.equals(receiver.getEmailStatus(), Receiver.Status.VERIFY)) {
            ReceiverConfig resp = new ReceiverConfig();
            resp.setChannelType(ChannelTypeEnum.EMAIL);
            resp.setToUser(receiver.getEmail());
            list.add(resp);
        }

        if (StringUtils.isNotEmpty(receiver.getWxMpOpenId())) {
            ReceiverConfig resp = new ReceiverConfig();
            resp.setChannelType(ChannelTypeEnum.WX_MP);
            resp.setToUser(receiver.getWxMpOpenId());
            list.add(resp);
        }
        return list;
    }
}
